package com.recruit.controller;

import com.recruit.model.NotifyDO;
import com.recruit.service.NotifyService;
import com.recruit.vo.CreatedVO;
import com.recruit.vo.UpdatedVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author DHF
 */
@RestController
@RequestMapping("/recruit/notify")
@Api(tags = "信息通知接口")
public class NotifyController {

    @Resource
    private NotifyService notifyService;

    /**
     * 新增消息通知
     *
     * @param notifyDO
     * @return
     */
    @PostMapping("")
    @ApiOperation(value = "新增消息通知")
    public CreatedVO create(
            @ApiParam(value = "通知信息实体", required = true)
            @RequestBody NotifyDO notifyDO) {
        notifyService.create(notifyDO);
        return new CreatedVO();
    }

    /**
     * 根据用户名修改消息状态为已读
     *
     * @param userName
     * @return
     */
    @PutMapping("")
    @ApiOperation(value = "根据用户名修改消息状态为已读")
    public UpdatedVO update(
            @ApiParam(value = "用户名", required = true)
            @RequestParam String userName) {
        notifyService.update(userName);
        return new UpdatedVO();
    }

    /**
     * 根据用户名和状态码查询该用户收到的所有通知
     *
     * @param userName
     * @param isRead
     * @return
     */
    @GetMapping()
    @ApiOperation(value = "根据用户名和状态码查询该用户收到的所有通知")
    public List<NotifyDO> get(
            @ApiParam(value = "用户名", required = true)
            @RequestParam String userName,
            @ApiParam(value = "是否读标记", required = true)
            @RequestParam String isRead) {
        return notifyService.get(userName, isRead);
    }

    /**
     * 根据用户名查询该用户收到的所有通知
     *
     * @param userName
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "根据用户名查询该用户收到的所有通知")
    public List<NotifyDO> getAll(
            @ApiParam(value = "用户名", required = true)
            @RequestParam String userName) {
        return notifyService.getAll(userName);
    }
}
